package org.nowcoder.leetcode.BSearch;

import java.util.Random;

/**
 * Title  : 278. First Bad Version
 * Source : https://leetcode.cn/problems/first-bad-version/description/
 * Author : XrazYang
 * Date   : 2023-10-31
 */

public class LeetCode_278 {
    private boolean isBadVersion(int version) {
        return new Random(10).nextBoolean();
    }

    public int firstBadVersion(int n) {
        int left = 0, right = n;
        while (left <= right) {
            int mid = left + ((right - left) >> 1);
            if (isBadVersion(mid)) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }
}
